import * as THREE from "three";

const createCamera = (context) => {
    let { container, scene } = context;
    var width = container.offsetWidth; //窗口宽度
    var height = container.offsetHeight; //窗口高度
    var k = width / height; //窗口宽高比
    var s = 40; //三维场景显示范围控制系数，系数越大，显示的范围越大
    //创建相机对象
    let camera = new THREE.PerspectiveCamera(s, width / height, 0.1, 1000);
    camera.position.set(250, 250, 250); //设置相机位置
    camera.up.set(0, 1, 0); //设置相机位置
    camera.lookAt(scene.position); //设置相机方向(指向的场景对象)

    // 初始化渲染器
    let renderer = new THREE.WebGLRenderer();
    renderer.setSize(container.offsetWidth, container.offsetHeight);//设置渲染区域尺寸
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
    renderer.outputEncoding=THREE.sRGBEncoding;
    container.appendChild(renderer.domElement); //body元素中插入canvas对象

    return { camera, renderer };
}

export default createCamera;